/**
 * Created by xx on 2016/6/29.
 */
var $ = require("jquery");
var av = require("../tools/av.js")($);
var baseService = require("./baseService.js")(av, $);

module.exports = function(){
    var loginService = av.util.clone(baseService);

    loginService.loginSubmit = function(username, password, promise){
        var dfd5 = $.Deferred();
        dfd5.done(function(data){
            promise.resolve(data);
        }).fail(function(code, msg){
            promise.reject(code, msg);
        });

        setTimeout(function () {
            if(username == "admin" && password == "123456"){
                dfd5.resolve({
                    id : "1",
                    username : username,
                    password : password
                });
            }else{
                dfd5.reject("10001", "用户名或者密码错误");
            }
        }, 1000);

    };

    loginService.loginSubmit2 = function(username, password, promise){
        this.doAjaxPromise({
            url : "",
            data : {
                username : username,
                password : password
            },
            method: "post"
        }, function(data, textStatus, jqXHR){
            if(data.state == 'ok'){
                promise.resolve(data.body);
            }else{
                promise.reject(data.code, data.msg);
            }
        }, function(jqXHR, textStatus, errorThrown){
            promise.reject("10000", "网络异常");
        });
    };

    return loginService;
};


